package com.qf.dao.impl;

import com.qf.dao.CustypeDao;

import com.qf.pojo.Custype;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class CustypeDaoImpl implements CustypeDao {
    QueryRunner qr=new QueryRunner(DataSourceUtil.getDataSource());

    @Override
    public List<Custype> findCustype() {
        String sql="select * from cus_type";
        try {
            return qr.query(sql,new BeanListHandler<>(Custype.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Custype findCustype(int cusTypeId) {
        String sql="select * from cus_type where cus_type_id=?";
        try {
            return qr.query(sql,new BeanHandler<>(Custype.class),cusTypeId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


}
